#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>

using std::cout;
using std::endl;
using std::vector;
using std::ostream_iterator;

int test0()
{
    vector<int> numbers{5, 1, 3, 2, 4, 66, 7, 4, 66, 66, 6, 9, 8};
    std::copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
    cout << "numbers'size:" << numbers.size() << endl;
    //执行remove函数之后，元素的数量并没有减少
    std::remove(numbers.begin(), numbers.end(), 66);
    cout << "\n执行remove操作之后:" << endl;
    std::copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));
    cout << "\nnumbers'size:" << numbers.size() << endl;

    return 0;
}

void test1()
{
    vector<int> numbers{5, 1, 3, 2, 4, 66, 7, 4, 66, 66, 6, 9, 8};
    std::copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
    cout << "numbers'size:" << numbers.size() << endl;
    //执行remove函数之后，元素的数量并没有减少
    auto it = std::remove(numbers.begin(), numbers.end(), 66);
    cout << "\n执行remove操作之后:" << endl;
    numbers.erase(it, numbers.end());
    std::copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));
    cout << "\nnumbers'size:" << numbers.size() << endl;
}

void test2()
{
    vector<int> numbers{5, 1, 3, 2, 4, 66, 7, 4, 66, 66, 6, 9, 8};
    std::copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
    cout << "numbers'size:" << numbers.size() << endl;
    //执行remove函数之后，元素的数量并没有减少
    cout << "\n执行remove操作之后:" << endl;
    //erase-remove惯用法
    numbers.erase(std::remove(numbers.begin(), numbers.end(), 66), 
                  numbers.end());
    std::copy(numbers.begin(), numbers.end(), ostream_iterator<int>(cout, " "));
    cout << "\nnumbers'size:" << numbers.size() << endl;
}

int main()
{
    /* test1(); */
    test2();
    return 0;
}
